package com.example.demo.study.lambda;

/**
 * lambda表达式中的变量访问
 */
public class LambdaTest5 {
    private static int j;
    private  int k;

    public static void main(String[] args) {
        LambdaTest5 lambdaTest5 = new LambdaTest5();
        lambdaTest5.test();
    }

    public void test(){
        int num = 10;
        j = 20;
        k = 30;
        //lambda表达式中可以访问成员变量也可以方法局部变量
        Action5 action5 = (i) -> System.out.println("操作后: i = " +(i+j+num+k));
        action5.run(1);

        //但是这个被访问的变量默认变为final修饰的 不可再改变 否则编译不通过
        //num = 60;
        j = 50;
        k = 70;
    }
}
interface Action5 {
    public void run(int i);
}